﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Frogism.Core;
using Frogism.Domain;
namespace Frogism.Tests
{
    [TestFixture]
    public class NetWorthTest
    {
      [Test]
      public void CreateNetWorthRetirement() {
        Assert.IsNotNull(NetWorthItem.CreateRetirement(GetEmptyAccountCollection()));
      }
      [Test]
      public void CreateNetWorthInvestment() {
        Assert.IsNotNull(NetWorthItem.CreateInvestment(GetEmptyAccountCollection()));
      }
        [Test]
        public void CreateNetWorthCash()
        {
        Assert.IsNotNull(NetWorthItem.CreateCash(GetEmptyAccountCollection()));
        }
        [Test]
        public void CreateNetWorthLiquid() {
          Assert.IsNotNull(NetWorthItem.CreateLiquid(GetEmptyAccountCollection()));
        }
        [Test]
        public void CreateNetWorthDebit() {
          Assert.IsNotNull(NetWorthItem.CreateDebit(GetEmptyAccountCollection()));
        }
        [Test]
        public void CreateNetWorthNetWorth() {
          Assert.IsNotNull(NetWorthItem.CreateNetWorth(GetEmptyAccountCollection()));
        }
        [Test]
        public void Balance() {
          Account a = new Account();
          a.Id = 1;
          a.AccountType = DBConst.AccountTypeSavings;
          Transaction t = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 100.99m, DateTime.Now.AddMonths(-1), true);
          a.Transactions.Add(t);

          Transaction t2 = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 120.05m, DateTime.Now, true);
          a.Transactions.Add(t2);

          Collection<IAccount> accounts = new Collection<IAccount>();
          accounts.Add(a);
          NetWorthItem netWorth = NetWorthItem.CreateCash(accounts);
          Assert.AreEqual(120.05m + 100.99m, netWorth.Balance);
        }
        [Test]
        public void PreviousMonth() {
          Account a = new Account();
          a.Id = 1;
          a.AccountType = DBConst.AccountTypeSavings;
          Transaction t = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 100.99M, DateTime.Now.AddMonths(-1), true);
          a.Transactions.Add(t);

          Transaction t2 = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 120.05m, DateTime.Now, true);
          a.Transactions.Add(t2);

          Collection<IAccount> accounts = new Collection<IAccount>();
          accounts.Add(a);
          NetWorthItem netWorth = NetWorthItem.CreateCash(accounts);
          Assert.AreEqual(100.99m, netWorth.PreviousMonth);
        }
        [Test]
        public void Progress() {

          DateTime startdate = new DateTime(2007, 10, 31);

          Account a = new Account();
          a.Id = 1;
          a.AccountType = DBConst.AccountTypeSavings;
          Transaction t = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 100.99M, startdate, true);
          a.Transactions.Add(t);

          Transaction t2 = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 34.77M, DateTime.Now.AddMonths(-1), true);
          a.Transactions.Add(t2);

          Transaction t3 = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 120.05m, DateTime.Now, true);
          a.Transactions.Add(t3);

          Collection<IAccount> accounts = new Collection<IAccount>();
          accounts.Add(a);
          NetWorthItem netWorth = NetWorthItem.CreateCash(accounts);
          Assert.AreEqual(t2.Amount + t3.Amount, netWorth.Progress);
        }
        private IAccount CreateAccount(int AccountType) {
          IAccount a = new Account();
          a.Id = 1;
          a.AccountType = AccountType;
          return a;
        }
        [Test]
        public void NetworthRetirementBalance() {
          IAccount a = CreateAccount(DBConst.AccountTypeRetirement);
          Transaction t = new Transaction("test", a.Id, DBConst.TransactionTypeDeposit, 9.99M, DateTime.Now, true);
          a.Transactions.Add(t);
        }
        [Test]
        public void NetworthNetworthBalance() {
          IAccount a = CreateAccount(DBConst.AccountTypeChecking);
          Transaction t = new Transaction("test", a.Id, DBConst.TransactionTypeDeposit, 9.99M, DateTime.Now, true);
          a.Transactions.Add(t);
        }
        [Test]
        public void Change() {
          IAccount a = CreateAccount(DBConst.AccountTypeChecking);

          Transaction t = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 100.99M, DateTime.Now.AddMonths(-1), true);
          a.Transactions.Add(t);

          Transaction t2 = new Transaction("test", 1, DBConst.TransactionTypeDeposit, 120.05m, DateTime.Now, true);
          a.Transactions.Add(t2);


          NetWorthItem netWorth = NetWorthItem.CreateCash(CreateAccountCollection(a));
            Assert.AreEqual(120.05m, netWorth.Change);
        }
        [Test]
        public void MoneyMangerGetNetWorthAll() {
          MoneyManager mm = new MoneyManager();
          Assert.IsNotNull(mm.GetNetWorth(mm.GetAll()),"Collection is null");
          Assert.AreEqual(6,mm.GetNetWorth(mm.GetAll()).Count, "Unexpected number of Networth Records.");
        }
        private Collection<IAccount> GetEmptyAccountCollection() {
          return new Collection<IAccount>();
        }
        private Collection<IAccount> CreateAccountCollection(IAccount account) {
          
          Collection<IAccount> collection = new Collection<IAccount>();
          collection.Add(account);
          return collection;

        }
    }
}
